package com.ruoyi.schedule.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.schedule.domain.Rule;
import com.ruoyi.schedule.service.IRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 排班规则Controller
 */
@RestController
@RequestMapping("/schedule/rule")
public class RuleController extends BaseController {
    @Autowired
    private IRuleService ruleService;

    /**
     * 查询排班规则列表
     */
    @PreAuthorize("@ss.hasPermi('schedule:rule:list')")
    @GetMapping("/list")
    public TableDataInfo list(Rule rule) {
        startPage();
        List<Rule> list = ruleService.selectRuleList(rule);
        return getDataTable(list);
    }

    /**
     * 新增排班规则
     */
    @PreAuthorize("@ss.hasPermi('schedule:rule:add')")
    @Log(title = "排班规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Rule rule) {
        return toAjax(ruleService.insertRule(rule));
    }

    /**
     * 修改排班规则
     */
    @PreAuthorize("@ss.hasPermi('schedule:rule:edit')")
    @Log(title = "排班规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Rule rule) {
        return toAjax(ruleService.updateRule(rule));
    }

    /**
     * 删除排班规则
     */
    @PreAuthorize("@ss.hasPermi('schedule:rule:remove')")
    @Log(title = "排班规则", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ruleIds}")
    public AjaxResult remove(@PathVariable Long[] ruleIds) {
        return toAjax(ruleService.deleteRuleByIds(ruleIds));
    }
}